package com.lingnan.tijian.service.impl;

import com.lingnan.tijian.domain.Checkitem;
import com.lingnan.tijian.domain.Setmeal;
import com.lingnan.tijian.dto.ApiResponse;
import com.lingnan.tijian.dto.SetmealAndCheckItemDto;
import com.lingnan.tijian.mapper.CheckitemMapper;
import com.lingnan.tijian.mapper.SetmealMapper;
import com.lingnan.tijian.service.ifac.SetmealService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class SetmealServiceImpl implements SetmealService {
    @Autowired
    SetmealMapper setmealMapper;

    @Autowired
    CheckitemMapper checkitemMapper;


    @Override
    public ApiResponse listSetmealAndCheckItem(Integer sex) {

        //最终要返回的数据
        List<SetmealAndCheckItemDto> setmealAndCheckItemDtoList=new ArrayList<>();

        //1.根据性别查询套餐列表  setmeal表
        List<Setmeal> setmealList=setmealMapper.selectByType(sex);

        //2。根据套餐的编号查询对应的检查项目编号列表  中间表
        //3.根据检查项列表数据去批量查询检查项明细数据    checkitem表
        //上面两步合成一步
        for(Setmeal st:setmealList){
            SetmealAndCheckItemDto setmealAndCheckItemDto=new SetmealAndCheckItemDto();
            setmealAndCheckItemDto.setSmId(st.getSmId());
            setmealAndCheckItemDto.setName(st.getName());
            setmealAndCheckItemDto.setPrice(st.getPrice());
            setmealAndCheckItemDto.setType(st.getType());

            List<Checkitem> checkItemList=checkitemMapper.selectCheckItemList(st.getSmId());

            setmealAndCheckItemDto.setCheckitemList(checkItemList);

            setmealAndCheckItemDtoList.add(setmealAndCheckItemDto); //尴尬。。。。。。
        }
        return new ApiResponse(ApiResponse.SUCCESS_STATUS,ApiResponse.SUCCESS_DESC,setmealAndCheckItemDtoList);
    }

    @Override
    public ApiResponse getSetmealById(Integer smId) {
        return new ApiResponse(ApiResponse.SUCCESS_STATUS,ApiResponse.SUCCESS_DESC,setmealMapper.selectByPrimaryKey(smId));
    }
}
